package com.ipbd.controller;

import com.ipbd.service.ActivityLogService;
import com.ipbd.service.CostBenefitService;
import com.ipbd.service.QuestionnaireService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.ipbd.service.ThoughtRecordService;
import com.ipbd.utils.R;
import com.ipbd.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dailyList")
@Slf4j
public class DailyListController {


    @Autowired
    private ActivityLogService activityLogService;
    @Autowired
    private ThoughtRecordService thoughtRecordService;
    @Autowired
    private CostBenefitService costBenefitService;


    /**
     * 获取当天活动日志（返回list）
     */
    @GetMapping("/getActivityLog")
    public R getActivityLog() {
        List<ActivityLogVo> activityLogList = activityLogService.getActivityLogList();

        return R.ok().put("activityLogList", activityLogList);
    }


    /**
     * 添加活动日志
     */
    @PostMapping("/saveActivityLog")
    public R saveQuestionnaire(@RequestBody ActivityLogForm activityLogForm) {
        activityLogService.saveActivityLog(activityLogForm);
        return R.ok();
    }

    /**
     * 获取当天的思维记录表
     */
    @GetMapping("/getThoughtRecords")
    public R getThoughtRecords() {
        List<ThoughtRecordVo> thoughtRecordList = thoughtRecordService.getThoughtRecords();
        return R.ok().put("thoughtRecords", thoughtRecordList);
    }




    /**
     * 添加思维记录表
     */
    @PostMapping("/saveThoughtRecord")
    public R saveThoughtRecord(@RequestBody ThoughtRecordVo thoughtRecordVo) {
        thoughtRecordService.saveThoughtRecords(thoughtRecordVo);
        return R.ok();
    }


    /**
     * 获取当天的成果效益表
     */
    @GetMapping("/getCostBenefit")
    public R getCostBenefits() {
        List<CostBenefitVo> costBenefitList = costBenefitService.getCostBenefits();
        return R.ok().put("costBenefitList", costBenefitList);
    }



    /**
     * 添加成果效益表
     */
    @PostMapping("/saveCostBenefit")
    public R saveCostBenefit(@RequestBody CostBenefitVo costBenefitVo) {
        costBenefitService.saveCostBenefit(costBenefitVo);
        return R.ok();
    }


    /**
     * 获取第 “几” 天
     */
    @GetMapping("/getWhatDay")
    public R getWhatDay() {
        int day = activityLogService.getWhatDay();
        return R.ok().put("day", day);
    }


    /**
     * 返回任务信息
     */
    @GetMapping("/getTaskData")
    public R getTaskData(@RequestParam String day,@RequestParam int TaskId) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = dateFormat.parse(day);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return R.ok().put("TaskDate", activityLogService.getTaskData(date, TaskId));
    }



}
